<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet"  th:href="@{/css/file.css}" />
    <link rel="stylesheet" type="text/css" th:href="@{/layui/css/layui.css}">
    <link th:href="@{/css/semantic.min.css}" rel="stylesheet">
    <script type="text/javascript" th:src="@{/layui/layui.js}"></script>
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
    <script th:src="@{/js/jquery-3.1.1.min.js}"></script>
    <script th:src="@{/js/semantic.min.js}">
    </script>
</head>
<body>
<div class="ui container" >
    <div class="ui segment">
        <form class="layui-form" method="post" enctype="multipart/form-data" th:action="@{/tea/center/my_icon/updatesubmit}">
            <div class="layui-form-item">
                <label class="layui-form-label">头像</label>
                <div class="layui-input-inline">
                    <a href="javascript:;" class="file">选择文件
                        <input type="file" name="icon" required lay-verify="required|image" autocomplete="off" id="user-image">
                    </a>
                </div>
                <!-- 显示图像预览 -->
                <img style="width: 180px;height: 180px;" class="ui large circular image" id="img" th:src="@{'/show/'+${user.getId()}}">
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit lay-filter="formDemo">提交</button>
                </div>
            </div>
        </form>
    </div>
</div>
</body>
<script>
    $(function(){
        //上传图像预览
        $('#user-image').on('change',function() {
            $('#img').attr('src', window.URL.createObjectURL(this.files[0]));
        });
    });

    layui.use('form', function(){
        var form = layui.form;
        form.verify({
            image: function (value, item) {
                if (!/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(value)) {
                    return '图片格式错误';
                }
            }
        })
    });
</script>
</html>